package com.woniuxy.hrp.service.Serviceimpl;

import com.woniuxy.hrp.entity.OrderUser;
import com.woniuxy.hrp.entity.Patient;
import com.woniuxy.hrp.mapper.OrderUserMapper;
import com.woniuxy.hrp.mapper.PatientMapper;
import com.woniuxy.hrp.service.OrderUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description：
 * @Author：曹杰克
 * @CreateTime：2022/8/29 20:55
 */
@Service("orderUserServiceimpl")
public class OrderUserServiceimpl implements OrderUserService {
    @Autowired
    OrderUserMapper orderUserMapper;
    @Autowired
    PatientMapper patientMapper;
    @Override
    public void add(OrderUser orderUser) {
//        List<OrderUser> orderUsers = orderUserMapper.selectByPatientId(orderUser.getPatient().getId());
//        if(orderUsers.size()<=5){ //就诊人默认为五个
            //若添加的就诊人设置为默认，将原先默认的就诊人改为n
//            if("y".equals(orderUser.getDef())){
//                for(int i=0;i<orderUsers.size();i++){
//                    if("y".equals(orderUsers.get(i).getDef())){
//                        OrderUser orderUser1=orderUsers.get(i);
//                        orderUser1.setDef("n");
//                        orderUserMapper.update(orderUser1);
//                    }
//                }
//            }
            orderUserMapper.add(orderUser);
//        }else{
            //抛异常（最大就诊人数为5）
//        }

    }

    @Override
    public void deleteById(int id) {
//        OrderUser orderUser = orderUserMapper.selectById(id);
        orderUserMapper.delete(id);
    }

    @Override
    public void updateById(OrderUser orderUser) {

        orderUserMapper.update(orderUser);
    }

    @Override
    public OrderUser getById(int id) {
        OrderUser orderUser = orderUserMapper.selectById(id);
        return orderUser;
    }

    @Override
    public List<OrderUser> selectAll(int patientId) {
//        Patient patient = patientMapper.selectById(patientId);
        List<OrderUser> orderUsers = orderUserMapper.selectByPatientId(patientId);
//        for (int i=0;i<orderUsers.size();i++){
//            orderUsers.get(i).setPatient(patient);
//        }

        return orderUsers;
    }
}
